import random

# 是否是豹子 指 3 个相同数字的牌型
def isbaozi(player_poker):
    # 222 333 ... kkk aaa
    if player_poker[0]["shijiIndex"] == player_poker[1]["shijiIndex"] and player_poker[1]["shijiIndex"] == \
            player_poker[2]["shijiIndex"]:
        return "豹子"
    # 同花顺 A23 234 10jq ... jqk AKQ
    # 是否是同花 a 2 3、 q k a
    istonghua = player_poker[0]["huaseIndex"] == player_poker[1]["huaseIndex"] and player_poker[0]["huaseIndex"] == \
                player_poker[2]["huaseIndex"]
    # 是否是顺子
    # 获得第一张牌的序号
    index1 = player_poker[0]["shijiIndex"]
    index2 = player_poker[1]["shijiIndex"]
    index3 = player_poker[2]["shijiIndex"]

    isshunzi = ((index1 + 1) % 13 == index2 and (index2 + 1) % 13 == index3 and index1 != 11) \
               or ((index1 + 1) % 13 == index3 and (index3 + 1) % 13 == index2 and index1 != 11) \
               or ((index3 + 1) % 13 == index1 and (index1 + 1) % 13 == index2 and index3 != 11) \
               or ((index2 + 1) % 13 == index1 and (index1 + 1) % 13 == index3 and index2 != 11) \
               or ((index3 + 1) % 13 == index2 and (index2 + 1) % 13 == index1 and index3 != 11) \
               or ((index2 + 1) % 13 == index3 and (index3 + 1) % 13 == index1 and index2 != 11)
    if istonghua and isshunzi:
        return "同花顺"
    if istonghua and not isshunzi:
        return "同花"
    if isshunzi and not istonghua:
        return "顺子"
    if index1 == index2 and index1 != index3 \
            or index1 == index3 and index1 != index2 \
            or index2 == index3 and index2 != index1:
        return "对子"
    return "单张"


huase = ['♦', '♣', '♥', '♠']
pockerDict = ["2",
              "3",
              "4",
              "5",
              "6",

              "7",
              "8",
              "9",
              "十",
              "J",

              "Q",
              "K",
              "A"]

while True:
    isTonghuashun = False
    # 扑克牌初始化
    poker_list = []
    for i in range(len(huase)):
        for j in range(len(pockerDict)):
            poker_list.append({"huaseIndex": i, "shijiIndex": j, "paimian": huase[i] + pockerDict[j], })

    # 使用列表生成式 生成了 五个玩家
    player_list = [{"name": f"player{i + 1}", "poker": []} for i in range(17)]

    # 发牌, 每人 3 张牌
    for player in player_list:
        for i in range(3):
            while True:
                x = random.randint(0, len(poker_list) - 1)
                if poker_list[x] in poker_list:
                    player.get("poker").append(poker_list[x])
                    poker_list.remove(poker_list[x])
                    break
        playerName = player.get("name")
        playerPoker = player.get("poker")
        paimian = playerPoker[0]["paimian"] + playerPoker[1]["paimian"] + playerPoker[2]["paimian"]
        print(f"{playerName}抽到了卡片 {paimian} 卡片类型：{isbaozi(playerPoker)}")
        isTonghuashun = isbaozi(playerPoker) == "同花顺"
        if isTonghuashun:
            break
    if isTonghuashun:
        break

# 豹子>同花顺>同花>顺子>对子>单张 遍历每个玩家找出最大值
# 是否是同花顺
# 是否是同花 同意花色
# 是否是顺子 三张连起来
# 是否是对子
# 否则是单张
